﻿using System;
using System.IO;
using System.Resources;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using KUMC.Neurology.SomatoTopo;

namespace KUMC.Neurology.SomatoTopo
{
    [Serializable]
    class Study
    {
        /*
         * Member Variable
         * */
        private string      m_Title = null;
        private string[]    m_SubjOpt = null;
        private string[]    m_DistOpt = null;
        private Layer       m_Template = null;

        private List<Subject> m_SubjList = null;

        /*
         * Constructor
         * */
        public Study(string title, string[] subjopt,
                        string[] distopt, Layer template)
        {
            this.m_Title        = title;
            this.m_SubjOpt      = subjopt;
            this.m_DistOpt      = distopt;
            this.m_Template     = template;
            this.m_SubjList     = new List<Subject>();
        }
                
        /*
         * Methods
         * */
        public void AddSubject(string[] option)
        {
            Subject subject = new Subject(option, m_Template.Size);
            m_SubjList.Add(subject);
        }
        public void AddSubject(string[] option, int[] distribution)
        {
            Subject subject = new Subject(option, distribution);
            m_SubjList.Add(subject);
        }
        public void AddSubject(Subject subject)
        {
            m_SubjList.Add(subject);
        }
        public void DelSubject(Subject subject)
        {
            m_SubjList.Remove(subject);
        }
        public void UpdateSubjects(Subject[] subjects)
        {
            this.m_SubjList = subjects.ToList<Subject>();
        }
        public void Export2DataTable(DataTable table)
        {
            try
            {
                for (int i = 0; i < this.m_SubjList.Count; i++)
                {
                    table.Rows.Add(this.m_SubjList[i].GetRow());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public Subject GetSubject(int index)
        {
            return this.m_SubjList[index];
        }
        public int GetSubjectCount()
        {
            return this.m_SubjList.Count;
        }
        public Subject[] GetSubjects()
        {
            return m_SubjList.ToArray();
        }

        /*
         * Getter
         * */
        public string Title
        {
            get
            {
                return this.m_Title;
            }
        }
        public string[] SubjectOption
        {
            get
            {
                return this.m_SubjOpt;
            }
        }
        public string[] DistributionOption
        {
            get
            {
                return this.m_DistOpt;
            }
        }
        public Layer Template
        {
            get
            {
                return this.m_Template;
            }
        }

    }
}